import turtle as t
wz = [[1, 45], [1, 25], [1, 5]]


def tcs():
    """贪吃蛇"""
    t.clear()
    for i in range(len(wz)):
        t.penup()
        t.goto(wz[i])
        t.pendown()
        t.dot(20, "gold")
    c_p = wz[-1].copy()
    if t.heading() == 0:
        c_p[0] += 20
    elif t.heading() == 90:
        c_p[1] += 20
    elif t.heading() == 180:
        c_p[0] -= 20
    elif t.heading() == 270:
        c_p[1] -= 20
    wz.append(c_p)
    wz.pop(0)
    t.ontimer(tcs, 200)
    print(t.heading())


def func_down():
    t.seth(270)


def func_up():
    t.seth(90)


def func_left():
    t.seth(180)


def func_right():
    t.seth(0)


if __name__ == '__main__':
    t.tracer(False)
    t.seth(270)
    tcs()
    t.onkeypress(func_down, "Down")
    t.onkeypress(func_up, 'Up')
    t.onkeypress(func_left, 'Left')
    t.onkeypress(func_right, 'Right')
    t.listen()
    t.done()
